package leetcode;

class 买卖股票的最佳时机II {
    public static void main(String[] args) {
        int res = maxProfit(new int[]{7,6,4,3,1});
        System.out.println(res);
    }
    private static int maxProfit(int[] prices) {
        int res=0;
        //思路：如果明天比今天的股票价格高，今天就买，然后明天卖出
        for (int i = 0; i < prices.length-1; i++) {
            if(prices[i+1]>prices[i]){
                //今天买入，明天卖出
                res+=prices[i+1]-prices[i];
            }
            else continue;
        }
        return res;
    }
}